package core;

import java.util.ArrayList;

public class HubwayStation {
	
	private int id;
	private float posLongitude;
	private float posLatitude;
	private String name;
	private String terminalName;
	
	private ArrayList<Trip> outgoingTrips;
	private ArrayList<Trip> incomingTrips;
	
	private int outgoingMeanDuration;
	private int outgoingMeanBirthdate;
	private int outgoingMeanGender;
	
	private int incomingMeanDuration;
	private int incomingMeanBirthdate;
	private int incomingMeanGender;
	
	public HubwayStation()
	{
		name = "";
		terminalName = "";
		outgoingTrips = new ArrayList<Trip>();
		incomingTrips = new ArrayList<Trip>();
	}

	public HubwayStation(int id, float posLongitude, float posLatitude,
			String name, String terminalName) {
		this();
		this.id = id;
		this.posLongitude = posLongitude;
		this.posLatitude = posLatitude;
		this.name = name;
		this.terminalName = terminalName;
	}

	public void calculateMeans()
	{
		int outgoingDurationSum = 0;
		int outgoingBirthdateSum = 0;
		int outgoingMaleCounter = 0;
		int outgoingFemaleCounter = 0;
		int outgoingNACounter = 0;
		for(Trip trip : outgoingTrips)
		{
			outgoingDurationSum += trip.getDuration();
			outgoingBirthdateSum += trip.getBirthDate();
			switch(trip.getGender())
			{
			case Trip.MALE:
				outgoingMaleCounter++;
				break;
			case Trip.FEMALE:
				outgoingFemaleCounter++;
				break;
			case Trip.NA:
				outgoingNACounter++;
				break;
			}
		}
		
		outgoingMeanDuration = outgoingDurationSum / outgoingTrips.size();
		outgoingMeanBirthdate = outgoingBirthdateSum / outgoingTrips.size();
		if(outgoingMaleCounter > outgoingFemaleCounter && outgoingMaleCounter > outgoingNACounter)
		{
			outgoingMeanGender = Trip.MALE;
		}
		else if(outgoingFemaleCounter > outgoingMaleCounter && outgoingFemaleCounter > outgoingNACounter)
		{
			outgoingMeanGender = Trip.FEMALE;
		}
		else
		{
			outgoingMeanGender = Trip.NA;
		}
	}

	public int getId() {
		return id;
	}

	public float getPosLongitude() {
		return posLongitude;
	}

	public float getPosLatitude() {
		return posLatitude;
	}

	public String getName() {
		return name;
	}

	public String getTerminalName() {
		return terminalName;
	}

	public ArrayList<Trip> getOutgoingTrips() {
		return outgoingTrips;
	}

	public ArrayList<Trip> getIncomingTrips() {
		return incomingTrips;
	}

	public int getOutgoingMeanDuration() {
		return outgoingMeanDuration;
	}

	public int getOutgoingMeanBirthdate() {
		return outgoingMeanBirthdate;
	}

	public int getOutgoingMeanGender() {
		return outgoingMeanGender;
	}

	public int getIncomingMeanDuration() {
		return incomingMeanDuration;
	}

	public int getIncomingMeanBirthdate() {
		return incomingMeanBirthdate;
	}

	public int getIncomingMeanGender() {
		return incomingMeanGender;
	}

	public int[] getOutgoingDurations()
	{
		int[] durations = new int[outgoingTrips.size() + 2];
		int min = Integer.MAX_VALUE;
		int max = 0;
		for(int i = 2; i < outgoingTrips.size() + 2; i++)
		{
			durations[i] = outgoingTrips.get(i - 2).getDuration();
			if(durations[i] < min)
			{
				min = durations[i];
			}
			if(durations[i] > max)
			{
				max = durations[i];
			}
		}
		
		durations[0] = min;
		durations[1] = max;
		return durations;
	}
	
	public int[] getOutgoingBirthdates()
	{
		int[] birthDates = new int[outgoingTrips.size() + 2];
		int min = Integer.MAX_VALUE;
		int max = 0;
		for(int i = 2; i < outgoingTrips.size() + 2; i++)
		{
			birthDates[i] = outgoingTrips.get(i - 2).getBirthDate();
			if(birthDates[i] < min)
			{
				min = birthDates[i];
			}
			if(birthDates[i] > max)
			{
				max = birthDates[i];
			}
		}
		birthDates[0] = min;
		birthDates[1] = max;
		return birthDates;
	}
	
	public int[] getOutgoingGenders()
	{
		int[] genders = new int[outgoingTrips.size() + 2];
		genders[0] = 0;
		genders[1] = 0;
		for(int i = 2; i < outgoingTrips.size(); i++)
		{
			genders[i] = outgoingTrips.get(i).getGender();
		}
		
		return genders;
	}
	
	public int[] getOutgoingSubscriptionTypes()
	{
		int[] types = new int[outgoingTrips.size() + 2];
		types[0] = 0;
		types[1] = 0;
		for(int i = 2; i < outgoingTrips.size(); i++)
		{
			types[i] = outgoingTrips.get(i).getSubscriptionType();
		}
		
		return types;
	}
	
	public int[] getIncomingDurations()
	{
		int[] durations = new int[incomingTrips.size() + 2];
		int min = Integer.MAX_VALUE;
		int max = 0;
		for(int i = 2; i < incomingTrips.size() + 2; i++)
		{
			durations[i] = incomingTrips.get(i - 2).getDuration();
			if(durations[i] < min)
			{
				min = durations[i];
			}
			if(durations[i] > max)
			{
				max = durations[i];
			}
		}
		
		durations[0] = min;
		durations[1] = max;
		return durations;
	}
	
	public int[] getincomingBirthdates()
	{
		int[] birthDates = new int[incomingTrips.size() + 2];
		int min = Integer.MAX_VALUE;
		int max = 0;
		for(int i = 2; i < incomingTrips.size() + 2; i++)
		{
			birthDates[i] = incomingTrips.get(i - 2).getBirthDate();
			if(birthDates[i] < min)
			{
				min = birthDates[i];
			}
			if(birthDates[i] > max)
			{
				max = birthDates[i];
			}
		}
		birthDates[0] = min;
		birthDates[1] = max;
		return birthDates;
	}
	
	public int[] getincomingGenders()
	{
		int[] genders = new int[incomingTrips.size() + 2];
		genders[0] = 0;
		genders[1] = 0;
		for(int i = 2; i < incomingTrips.size(); i++)
		{
			genders[i] = incomingTrips.get(i).getGender();
		}
		
		return genders;
	}
	
	public int[] getincomingSubscriptionTypes()
	{
		int[] types = new int[incomingTrips.size() + 2];
		types[0] = 0;
		types[1] = 0;
		for(int i = 2; i < incomingTrips.size(); i++)
		{
			types[i] = incomingTrips.get(i).getSubscriptionType();
		}
		
		return types;
	}

	public void addOutgoingTrip(Trip trip) {
		outgoingTrips.add(trip);
		
	}
	
	public void addIncomingTrip(Trip trip) {
		incomingTrips.add(trip);
		
	}
	
}
